/**
 * 
 */
package furniture.items3d.model.tessellation;

import javax.vecmath.Vector3d;

import furniture.items3d.bounds.Bounds3d;
import furniture.items3d.model.BoxPrimitive;
import furniture.items3d.model.CuboidPrimitive;
import furniture.items3d.model.LayedPrimitive;
import furniture.items3d.model.LayingModel;
import furniture.items3d.model.PipePrimitive;
import furniture.render3d.TriangleSet;


/**
 * @author Grill Balazs (balage.g@gmail.com)
 *
 */
public class Tessellator {

	protected Bounds3d bounds;
	
	protected PipeTessellator pipes;
	
	protected BoxTessellator boxes;
	
	protected CuboidTessellator cuboids;
	
	/**
	 * Direction of light
	 */
	public static Vector3d light = new Vector3d(1,-1,0);
	
	public Tessellator(Bounds3d bounds){
		this.bounds = bounds;
		pipes = new PipeTessellator(bounds);
		boxes = new BoxTessellator(bounds);
		cuboids = new CuboidTessellator();
	}
	
	/**
	 * Generate triangles of a model
	 * @param model
	 * @return
	 */
	public TriangleSet tessellate(LayingModel model){
		ItemSet result = new ItemSet();
		
		for(LayedPrimitive p : model.getPrimitives()){
			if (p instanceof PipePrimitive)
				result.addSet(pipes.tessellate((PipePrimitive)p));
			if (p instanceof BoxPrimitive)
				result.addSet(boxes.tessellate((BoxPrimitive)p));
			if (p instanceof CuboidPrimitive)
				result.addSet(cuboids.tessellate((CuboidPrimitive)p));
		}
			
		return result;
	}	
	
}
